package com.ass.database.constants;

import com.ass.database.builder.DbBuilder;
import com.ass.database.builder.MySQLBuilder;
import lombok.Getter;

import java.util.Arrays;

/**
 *
 *
 * @author : liyong
 * @date : 2024-02-20 14:29
 * @since :1.0
 **/
@Getter
public enum SourceEnum {

//    ORACLE("01", "oracle","Oracle", "oracle", new MySQLBuilder()),
    MySQL("02", "mysql","MySQL", "mysql", new MySQLBuilder()) ,
//    PGSQL("03" ,"postgres","PostgreSQL", "postgresql", new PostgreSQLUtil()) ,
//    CLICK("04" ,"clickhouse","ClickHouse", "clickhouse", new MySQLUtil()),
//    PAIMON("05" ,"paimon","PAIMON", "paimon", new PaimonUtil()),
    ;
    private String  code;

    private String driver;
    private String uppercase;
    private String lowercase;

    private DbBuilder dbBuilder;


    SourceEnum(String code, String driver, String uppercase, String lowercase, DbBuilder dbBuilder) {
        this.code = code;
        this.uppercase = uppercase;
        this.lowercase = lowercase;
        this.dbBuilder = dbBuilder;
        this.driver = driver;
    }

    /**
     * 获取对应的code的全部属性
     * @param code
     * @return
     */
    public static SourceEnum getDataSourceEnum(String code) {
        return Arrays.stream(SourceEnum.values()).filter(source->source.code.equals(code)).findFirst().orElse(null);
    }

    /**
     * 获取对应的code的使用方法
     *
     * @author: Li yong
     * @date: 2024/2/26 9:34
     * @param code:
     * @return: com.sx.util.connectUtil.DbUtil
     */
    public static DbBuilder getEnumOverride(String code) {
        return Arrays.stream(SourceEnum.values())
                .filter(source->source.code.equals(code))
                .map(SourceEnum::getDbBuilder)
                .findFirst().orElse(null);
    }

    /**
     * 获取小写lowercase的全部属性
     *
     * @author: Li yong
     * @date: 2024/3/21 10:09
     * @param lowercase:
     * @return: com.sx.common.SourceEnum
     */
    public static SourceEnum getDataSourceEnumByLower(String lowercase) {
        return Arrays.stream(SourceEnum.values())
                .filter(source->source.lowercase.equals(lowercase))
                .findFirst().orElse(null);
    }

    /**
     * 获取小写lowercase的使用方法
     *
     * @author: Li yong
     * @date: 2024/3/21 10:10
     * @param lowercase:
     * @return: com.sx.util.connectUtil.DbUtil
     */
    public static DbBuilder getOverrideByLowercase(String lowercase) {
        return Arrays.stream(SourceEnum.values())
                .filter(source->source.lowercase.equals(lowercase))
                .map(SourceEnum::getDbBuilder)
                .findFirst().orElse(null);
    }

}
